package com.lcm.basic.p9;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;

/**
 * @author Coder-lcm
 * @date 2021/4/4
 */
public class SystemDemo {
    public static void main(String[] args) throws IOException {
        // 1. 获取系统所有的环境变量
        Map<String, String> env = System.getenv();
        env.forEach((k,v) -> {
            System.out.println(k + ": " + v);
        });
        // 1.1 获取特定环境变量的值
        System.out.println("Java-Home--" + System.getenv("JAVA_HOME"));

        System.out.println("++++++++++++++++++++++++++++++++=");

        // 2. 获取所有的系统属性
        Properties properties = System.getProperties();
        properties.forEach((k, v) -> {
            System.out.println(k + ": " + v);
        });

        // 2.1 将所有的系统属性打印到文件props.txt中
        properties.store(new FileOutputStream("props.txt"), "System Properties");
        // 2.2输出特定的系统属性
        System.out.println("os name:　" + System.getProperty("os.name"));
    }

}
